import request from '../../utils/request'

interface LoginDto {
  phone: string
}
interface UpdateDto {
  avatar: string
  nickName: string
}
export interface RecudeCountDto {
  id: string // 车源或者线索id
  userId: string //用户id
  reduceCoin: number
}

/**微信用户登录 */
export const wxLogin = (data: LoginDto) => request('/api/wxuser/login', 'POST', data)

/**微信用户更新资料 */
export const wxUpdate = (id: string, data: UpdateDto) => request(`/api/wxuser/${id}`, 'POST', data) as Promise<Result<WxUser>>

/**
 * 
 * @param {number} id 用户id
 * @param { id: number, day: number } data 增加天数
 */
export const beVip = (id: string, data: { id: string, day: number, discount: number, bonusCoins: number }) => request(`/api/wxuser/addVip/${id}`, 'POST', data) as Promise<Result<WxUser>>

export const checkExpireVip = (id: string) => request(`/api/wxuser/expire/${id}`, 'GET') as Promise<Result<boolean>>

export const getUserDetail = (id: string) => request(`/api/wxuser/detail/${id}`, 'GET') as Promise<Result<WxUser>>

/**
 * 充值积分
 * @param {number} id 用户ID
 * @param {count: number} data 增加积分
 */
export const addUserCoin = (id: string, data: { coin: number }) => request(`/api/wxuser/addCoin/${id}`, 'POST', data) as Promise<Result<WxUser>>

/**
 * 减少次数并添加获取车源记录
 * @param data 
 */
export const reduceCountByChannel = (data: RecudeCountDto) => request(`/api/wxuser/reduce/channel`, 'POST', data) as Promise<Result<WxUser>>

/**
 * 减少次数并添加获取线索记录
 * @param data 
 */
export const reduceCountByClue = (data: RecudeCountDto) => request(`/api/wxuser/reduce/clue`, 'POST', data) as Promise<Result<WxUser>>

/**
 * 减少次数并添加获取同行车源记录
 * @param data 
 */
export const reduceCountByPeer = (data: RecudeCountDto) => request(`/api/wxuser/reduce/peer`, 'POST', data) as Promise<Result<WxUser>>

/**
 * 检查用户是否已购买车源
 * @param {number} id 
 * @param {number} userId 
 */
export const checkChannel = (id: string, userId: string) => request(`/api/wxuser/check/channel?id=${id}&userId=${userId}`, 'GET') as Promise<Result<boolean>>

/**
 * 检查用户是否已购买线索
 * @param {number} id 
 * @param {number} userId 
 */
export const checkClue = (id: string, userId: string) => request(`/api/wxuser/check/clue?id=${id}&userId=${userId}`, 'GET') as Promise<Result<boolean>>

/**
 *  检查用户是否已购买车源
 *  @param {number} id 
 *  @param {number} userId 
 */
export const checkPeer = (id: string, userId: string) => request(`/api/wxuser/check/peer?id=${id}&userId=${userId}`, 'GET') as Promise<Result<boolean>>


export interface MyChannel {
  id: string
  channelName: string
  brand: string
  mileage: number
  registrationDate: string
  homeLocation: string
  channelId: string
  userId: string
}
/**
 * 获取我的车源记录
 * @param {number} id 
 */
export const getMyChannel = (id: string) => request(`/api/wxuser/myChannel?id=${id}`, 'GET') as Promise<Result<MyChannel>>

export interface MyClue {
  id: string
  clueName: string
  brand: string
  location: string
  clueId: string
  userId: string
}

/**
 * 获取我的线索记录
 * @param {number} id 
 */
export const getMyClue = (id: string) => request(`/api/wxuser/myClue?id=${id}`, 'GET') as Promise<Result<MyClue>>

export interface MyPeer {
  id: string
  brand: string
  carName: string
  mileage: number
  registrationDate: string
  homeLocation: string
  peerId: string
  userId: string
}
/**
 * 获取我的同行车源记录
 * @param {number} id 
 */
export const getMyPeer = (id: string) => request(`/api/wxuser/myPeer?id=${id}`, 'GET') as Promise<Result<MyPeer>>